<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/21
 * Time: 14:47
 */
namespace app\api\controller\v1;
use app\common\model\GoldOrder as Order;

class Goldorder extends Base {
    private $model;
    public function _initialize(){
        parent::_initialize();
        $this->model = new Order;
    }
    //购买具体业务
    public function buyBusiness(){
        if($this->request->isPost()){

            $post = input('post.');
            $this->isLogin($post);
            $uid = isset($post['uid'])? ($post['uid']):'';
            $bid = isset($post['bid'])? ($post['bid']):'';
            $pay_gold = isset($post['pay_gold'])? ($post['pay_gold']):'';
            $account = isset($post['account'])?($post['account']):'';
            $number = isset($post['number'])? ($post['number']):'';

            $data = [
                'uid'=>$uid,
                'bid'=>$bid,
                'pay_gold'=>$pay_gold,
                'account'=>$account,
                'number' =>$number,
            ];
            $validate = validate('Goldorder');
            if(!$validate->check($data)){
                return show(400,$validate->getError());
            }
            $post['create_time'] = time();
            $post['out_trade_no'] = 'gold'.date('ymdHis').uniqid();
            //金币订单表
            $res = $this->model->saveorder($post);
            if(!$res){
                return show(400,'购买服务失败');
            }

            return show(200,'购买服务成功');


        }

    }

    /**
     * 获取消费记录
     * @return mixed
     */
    public function getExpense(){
        if($this->request->isPost()){
            $post = input('post.');

            $this->isLogin($post);

            $res = model('GoldOrder')->getExpense($post);
            return $res;
        }
    }
}